package com.cc.bsp.action.common.query;

import java.util.List;

import com.cc.bsp.action.IQueryAction;
import com.cc.bsp.domain.Domain;
import com.cc.bsp.exception.ActionWebException;
import com.cc.bsp.exception.DomainException;
import com.cc.bsp.persistence.dao.IQueryPageOrder;
import com.opensymphony.xwork2.ActionSupport;

public class CommonQueryAction extends ActionSupport implements IQueryAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7905995289948563759L;

	private IQueryPageOrder pageOrder;
	
	private List<Domain> domains;
	
	private Domain domain;
	
	private void page() {
		domain.setPageOrder(pageOrder);
	}

	public String findById() throws ActionWebException {

		try {
			page();
			domain = domain.findById();
		} catch (DomainException e) {
			e.printStackTrace();
			throw new ActionWebException(e);
		}

		return ActionSupport.SUCCESS;
	}

	public String findOne() throws ActionWebException {

		try {
			page();
			domain = domain.findOne();
		} catch (DomainException e) {
			e.printStackTrace();
			throw new ActionWebException(e);
		}

		return ActionSupport.SUCCESS;
	}

	public String findList() throws ActionWebException {

		try {
			page();
			domains = domain.findList();
		} catch (DomainException e) {
			e.printStackTrace();
			throw new ActionWebException(e);
		}

		return ActionSupport.SUCCESS;
	}

	public String findAll() throws ActionWebException {
		try {
			page();
			domains = domain.findAll();
		} catch (DomainException e) {
			e.printStackTrace();
			throw new ActionWebException(e);
		}
		return ActionSupport.SUCCESS;
	}
	

	public String execute() throws Exception {

		return super.execute();
	}

	public Domain getDomain() {
		return domain;
	}

	public void setDomain(Domain domain) {
		this.domain = domain;
	}

	public List<Domain> getDomains() {
		return domains;
	}

	public void setDomains(List<Domain> domains) {
		this.domains = domains;
	}

	public IQueryPageOrder getPageOrder() {
		return pageOrder;
	}

	public void setPageOrder(IQueryPageOrder pageOrder) {
		this.pageOrder = pageOrder;
	}
	
	
	

}
